Skip to content

JIT: Coalesce stores from struct copies#130535

Merged
EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:egor/jit-struct-store-coalescing
Jul 13, 2026
Merged

JIT: Coalesce stores from struct copies#130535
EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:egor/jit-struct-store-coalescing

Conversation

@EgorBo

@EgorBo EgorBo commented Jul 10, 2026

Copy link
Copy Markdown
Member

Allows existing store coalescing to merge non-GC field stores produced by struct copies.

Int128 _fld;

void Foo1(out Int128 x) => x = new Int128(2L, 1L);

void Foo2() => _fld = 123456789;
 Foo1:
- mov      qword ptr [rdx], 1
- mov      qword ptr [rdx+0x08], 2
+ vmovups  xmm0, xmmword ptr [reloc @RWD00]
+ vmovups  xmmword ptr [rdx], xmm0

 Foo2:
- mov      qword ptr [rcx+0x08], 0x75BCD15
- xor      eax, eax
- mov      qword ptr [rcx+0x10], rax
+ vmovss   xmm0, dword ptr [reloc @RWD00]
+ vmovups  xmmword ptr [rcx+0x08], xmm0

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f267b92e-719f-4b0d-b19f-eab8f97611f5
Copilot AI review requested due to automatic review settings July 10, 2026 23:16
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 10, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates JIT copy-block morphing so that when a struct copy is expanded into multiple field stores, the non-GC field STOREIND nodes are marked with GTF_IND_ALLOW_NON_ATOMIC. This enables existing lowering-time store coalescing to legally merge adjacent non-volatile stores (e.g., two 8-byte stores into one 16-byte SIMD store) without being blocked by atomicity constraints.

Changes:

  • In MorphCopyBlockHelper::CopyFieldByField, mark per-field indirect stores as GTF_IND_ALLOW_NON_ATOMIC when they originate from a copyBlk and the field type is not GC (!varTypeIsGC(srcType)).
  • This allows Lowering’s store coalescing (LowerStoreCoalescing / LowerCheckCoalescedStoreAtomicity) to treat these adjacent stores as eligible for wider, potentially unaligned, non-atomic combined stores.

@EgorBo

EgorBo commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

@MihuBot -nuget

@EgorBo

EgorBo commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

PTAL @jakobbotsch @dotnet/jit-contrib

I just assume that if we move a struct from A to B and promote it to individual stores, we can give up on atomicity guarantees for them

@EgorBo EgorBo requested a review from jakobbotsch July 13, 2026 11:49
@EgorBo

This comment was marked as outdated.

@EgorBo EgorBo marked this pull request as ready for review July 13, 2026 11:52
Comment thread src/coreclr/jit/morphblock.cpp Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 572375cc-ea86-40c2-9aef-a17eda0d581a
Copilot AI review requested due to automatic review settings July 13, 2026 12:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/promotiondecomposition.cpp
Comment thread src/coreclr/jit/promotiondecomposition.cpp
@EgorBo EgorBo enabled auto-merge (squash) July 13, 2026 17:57
@EgorBo EgorBo merged commit 36d2424 into dotnet:main Jul 13, 2026
140 checks passed
@EgorBo EgorBo deleted the egor/jit-struct-store-coalescing branch July 13, 2026 17:57
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants